package common.util.string;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 
 * 日期工具类
 * <p>
 * Title: DateUtils.java
 * </p>
 * <p>
 * Description:培训师平台
 * </p>
 * <p>
 * Copyright: Copyright (c) 2011
 * </p>
 * <p>
 * Company:北京千家在线
 * </p>
 * 
 * @author miaoyouhu
 * @date Jun 20, 2011 3:04:53 PM
 * @version V1.0
 */
public class DateUtils {

	/**
	 * 获得上周日的日期;
	 * 
	 * @return
	 */
	public static String getLastSunday() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.DAY_OF_WEEK, 1);
		return sdf.format(cal.getTime());
	}

	/**
	 * 获得上周结束的日期;(上周六)
	 * 
	 * @return
	 */
	public static String getLastEnd() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.WEEK_OF_MONTH, -1);
		cal.set(Calendar.DAY_OF_WEEK, 7);
		return sdf.format(cal.getTime());
	}

	/**
	 * 获得上周开始的日期;(上上周日)
	 * 
	 * @return
	 */
	public static String getLastStart() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.WEEK_OF_MONTH, -1);
		cal.set(Calendar.DAY_OF_WEEK, 1);
		return sdf.format(cal.getTime());
	}

	/**
	 * 获得本周开始的日期;(上周日)
	 * 
	 * @return
	 */
	public static String getCurrentStart() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.DAY_OF_WEEK, 1);
		return sdf.format(cal.getTime());
	}

	/**
	 * 获得本周结束的日期;(本周六)
	 * 
	 * @return
	 */
	public static String getCurrentEnd() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.DAY_OF_WEEK, 7);
		return sdf.format(cal.getTime());
	}

	

	/**
	 * 获得上周一的日期;
	 * 
	 * @return
	 */
	public static String getLastMonday() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.WEEK_OF_MONTH, -1);
		cal.set(Calendar.DAY_OF_WEEK, 2);
		return sdf.format(cal.getTime());
	}

	/**
	 * 获得上个月的第一天的日期;
	 * 
	 * @return
	 */
	public static String getLastMonthFrist() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MONTH, -1);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return sdf.format(cal.getTime());
	}

	/**
	 * 获得上个月的最后一天的日期;
	 * 
	 * @return
	 */
	public static String getLastMonthLast() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.add(cal.MONTH, -1);
		int value = cal.getActualMaximum(cal.DAY_OF_MONTH);
		cal.set(cal.DAY_OF_MONTH, value);
		return sdf.format(cal.getTime());
	}
	
	public static void main(String[] args) {
		System.out.println(DateUtils.getMonthEnd());
	}

	/**
	 * 获得本月的第一天的日期;
	 * 
	 * @return
	 */
	public static String getMonthFrist() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return sdf.format(cal.getTime());
	}

	/**
	 * 获得本月的最后一天的日期;
	 * 
	 * @return
	 */
	public static String getMonthEnd() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		int value = cal.getActualMaximum(cal.DAY_OF_MONTH);
		cal.set(cal.DAY_OF_MONTH, value);
		return sdf.format(cal.getTime());
	}

	/**
	 * 获得今天的日期;
	 * 
	 * @return
	 */
	public static String getNowDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		return sdf.format(cal.getTime());
	}

}
